package com.hucc.api.controller;

import com.alibaba.fastjson.JSON;
import com.hucc.api.domain.exceptions.BusinessException;
import com.hucc.api.domain.req.CaseReq;
import com.hucc.api.domain.req.GroupReq;
import com.hucc.api.domain.res.ApiResult;
import com.hucc.api.service.CaseService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@Api("case相关接口")
@RestController
@RequestMapping("/case")
public class CaseController {
    @Autowired
    CaseService caseService;


    @ApiOperation(value = "添加case")
    @PostMapping("add")
    public ApiResult<Void> add(@RequestBody CaseReq caseReq) {

        try {
            caseService.add(caseReq);
            return ApiResult.success();
        } catch (BusinessException e) {
            log.error("add case error, caseReq: {}", JSON.toJSONString(caseReq), e);
            return ApiResult.fail(e.getMessage());
        } catch (Exception e) {
            log.error("add case error, caseReq: {}", JSON.toJSONString(caseReq), e);
            return ApiResult.fail("添加case失败");

        }
    }
}
